﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections.Generic;
using BetterImageProcessor;
using BetterImageProcessorIndexedResizing;
using BetterImageProcessorQuantization;
using LIB;
using System.Drawing.Imaging;


public partial class admin_upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        System.Drawing.Image thumbnail_image = null;
        System.Drawing.Image original_image = null;
        System.Drawing.Bitmap final_image = null;
        System.Drawing.Graphics graphic = null;
        MemoryStream ms = null;

        try
        {
            // Get the data
            HttpPostedFile jpeg_image_upload = Request.Files["Filedata"];
            Response.StatusCode = 200;
            ImageProcessor.Resize(jpeg_image_upload.InputStream, 300, 300, ResizeQuality.HighSpeed).Save(new System.Web.Services.WebService().Server.MapPath(App_Constant.PATH_UP_CONTENT + "/") + jpeg_image_upload.FileName, ImageFormat.Jpeg);
            jpeg_image_upload.SaveAs(new System.Web.Services.WebService().Server.MapPath(App_Constant.PATH_UP_IMAGE + "/") + jpeg_image_upload.FileName);
            
            Response.Write(jpeg_image_upload.FileName + "|");

        }
        catch (Exception ex)
        {
            // If any kind of error occurs return a 500 Internal Server error
            Response.StatusCode = 500;
            Response.Write("An error occured");
            Response.End();
        }
        finally
        {
            // Clean up
            if (final_image != null) final_image.Dispose();
            if (graphic != null) graphic.Dispose();
            if (original_image != null) original_image.Dispose();
            if (thumbnail_image != null) thumbnail_image.Dispose();
            if (ms != null) ms.Close();
            Response.End();
        }

    }
}